import type { Next, Context } from 'koa';
import { vailParams } from '@/helpers/vailParams';
import { createResponse, sendSuccess, sendError, sendBadRequest } from '@/helpers/response';

export const globalMiddleware = async (ctx: Context, next: Next) => {
  ctx.vailParams = vailParams;
  ctx.sendError = createResponse(ctx, sendError);
  ctx.sendSuccess = createResponse(ctx, sendSuccess);
  ctx.sendBadRequest = createResponse(ctx, sendBadRequest);
  // 平台
  ctx.platform = ctx.headers['platform'] as Context['platform'];
  await next();
}